package com.example.day2.mvvm.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

public abstract class BaseFragment <VDB extends ViewDataBinding,VM extends BaseViewModel> extends Fragment {
    protected VDB binding;
    protected VM viewModel;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater,bindLayoutId(),container,false);
        viewModel = new ViewModelProvider(getActivity()).get(getVIewModel());
        initView();
        initData();
        return binding.getRoot();
    }

    public abstract void initView();

    public abstract void initData();

    public abstract Class<VM> getVIewModel();

    public abstract int bindLayoutId();
}
